{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "545e900d-3100-4194-bf9b-b88906ac4a47",
   "metadata": {},
   "outputs": [],
   "source": [
    "import gymnasium as gym\n",
    "from math import pi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "62fded87-5206-499d-bbc6-1c17d6b1078e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([ 0.03045513, -0.04510251, -0.02661009,  0.04716783], dtype=float32),\n",
       " {})"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "env = gym.make('CartPole-v1', render_mode=\"human\")\n",
    "env.reset()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "48581c79-2d36-4632-ab12-bc4cd6758936",
   "metadata": {},
   "outputs": [],
   "source": [
    "myAction = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "8151a512-244c-4580-9b42-224d65326fa7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-0.025666729\n",
      "-0.019039975\n",
      "-0.0067236284\n",
      "0.0113252355\n",
      "0.03518534\n",
      "0.053263206\n",
      "0.06571269\n",
      "0.0726533\n",
      "0.074168734\n",
      "0.07030606\n",
      "0.0610755\n",
      "0.046450537\n",
      "0.026368521\n",
      "0.00073167833\n",
      "-0.030591393\n",
      "-0.06776356\n",
      "-0.099275105\n",
      "-0.12537062\n",
      "-0.14626554\n",
      "-0.16214357\n",
      "-0.17315504\n",
      "-0.17941596\n",
      "-0.1810076\n",
      "-0.17797638\n",
      "-0.17033394\n",
      "-0.15805733\n",
      "-0.14108945\n",
      "-0.11933952\n",
      "-0.092683725\n",
      "-0.060966283\n",
      "-0.024000838\n",
      "0.018427515\n",
      "0.06655932\n",
      "0.10895176\n",
      "0.14591624\n",
      "0.17774154\n",
      "0.20468979\n",
      "0.22699367\n"
     ]
    }
   ],
   "source": [
    "while True:\n",
    "    env.render()\n",
    "    # action = env.action_space.sample()\n",
    "    observation, reward, terminated, truncated, info = env.step(myAction)\n",
    "\n",
    "    cartPosition = observation[0]\n",
    "    cartVelocity = observation[1]\n",
    "    poleAngle = observation[2]\n",
    "    poleAngleVelocity = observation[3]\n",
    "    print(poleAngle)\n",
    "\n",
    "    if poleAngle < 0:\n",
    "        myAction = 0\n",
    "    else:\n",
    "        myAction = 1\n",
    "\n",
    "    if terminated:\n",
    "        # env.reset()\n",
    "        break\n",
    "    if truncated:\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "fc327fd7-7034-48b3-a2e7-9ce210287c5d",
   "metadata": {},
   "outputs": [],
   "source": [
    "env.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "88c26f73-48b9-47bd-b9d7-27b1c3538032",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
